package top.wenzz.manage.system.manage.web;

import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import top.wenzz.commons.utils.ExceptionUtils;
import top.wenzz.commons.utils.SpringSecurityUtils;
import top.wenzz.commons.vo.PageRequest;
import top.wenzz.commons.vo.RetMsg;
import top.wenzz.commons.web.BasicCrudController;
import top.wenzz.manage.system.manage.entity.OvertimeRecord;
import top.wenzz.manage.system.manage.entity.SysUser;
import top.wenzz.manage.system.manage.service.OvertimeRecordService;

import java.util.List;

/**
 * 加班记录controller
 * Created by 钟廷员 on 2016/12/15.
 */
@RestController
@RequestMapping("overtime/record")
public class OvertimeRecordController extends BasicCrudController<OvertimeRecord, OvertimeRecordService> {
    @Override
    public Object save(@RequestBody OvertimeRecord entity) {
        entity.setUser(SysUser.builder().id(SpringSecurityUtils.getUserByContext().getId()).build());
        return super.save(entity);
    }

    @Override
    public Object update(OvertimeRecord entity) {
        return RetMsg.error();
    }

    @RequestMapping( value = "batchSave", method = RequestMethod.POST )
    public Object batchSave(@RequestBody List<OvertimeRecord> entitys) {
        String ret;
        try {
            ret = service.batchSave(entitys);
        } catch (Exception e) {
            ret = ExceptionUtils.getExceptionMsg(e);
        }
        return ret(ret, "增加成功");
    }

    @Override
    public Object find(@RequestBody OvertimeRecord entity, PageRequest pageRequest) {
        entity.setUser(SysUser.builder().id(SpringSecurityUtils.getUserByContext().getId()).build());
        return super.find(entity, pageRequest);
    }
}
